package com.chenjie.executor.day20;


import org.springframework.util.StringUtils;

/**
 * packageName com.chenjie.executor.day14
 *
 * @author chenjie
 * @version JDK 8
 * @className TicketTask (此处以class为例)
 * @date 2024/5/28
 * @description TODO
 */
public class Consumer implements Runnable {

private Data data;

    public Consumer(Data data) {
        this.data = data;
    }
    @Override
    public void run() {
        while (true){
            synchronized (data) {
                try {
                    if(!StringUtils.isEmpty(data.getMessage())){
                        System.out.println("读取值为"+data.getMessage());
                        data.setMessage(null);
                    }
                    //唤醒生产者线程
                    data.notify();
                    //使当前线程等待
                    data.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

            }
        }

        }


    }

